home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 11 - 1995 / 11.04 Apr 95 / TreeAppƒ / Eric's C++ Libraries / Interface Classes / CPPDialogText.cp < prev    next >
Encoding:
Text File  |  1996-04-04  |  3.3 KB  |  125 lines  |  [TEXT/KAHL]

  1. /********************************************************* DEFINITION
  2.     DATE:    9/28/93
  3.     AUTHOR: Eric R. Rosé
  4.     
  5.     CLASS:  CPPDialogText
  6.     
  7.     SUPERCLASS: CPPFilterText
  8.     
  9.         This C++ class manages a textedit area with no scrollbars and
  10.         a length limit of 255 characters.
  11.     
  12. ********************************************************************/
  13.  
  14. #include <CPPDialogText.h>
  15.  
  16. /*-----------------------------------------------------------------*/
  17. /*------------------------ PUBLIC METHODS -------------------------*/
  18. /*-----------------------------------------------------------------*/
  19.  
  20.     CPPDialogText::CPPDialogText (CPPWindow *OurWindow,
  21.                                    Rect *itsBounds,
  22.                                    StringPtr defaultString,
  23.                                    int maxLength,
  24.                                    int Font,
  25.                                    int FSize) :
  26.                    CPPFilterText (OurWindow, itsBounds, itsBounds,
  27.                                      maxLength, block, (int)none, FALSE,
  28.                                      FALSE, Font, FSize)
  29.     {
  30.         if (defaultString)
  31.           SetToString (defaultString);
  32.           
  33.         SetFilterString ("\p\r");    // no returns allowed
  34.     }
  35.  
  36. /*-----------------------------------------------------------------*/
  37.  
  38.     CPPDialogText::CPPDialogText (CPPWindow *OurWindow,
  39.                                    Rect *itsBounds,
  40.                                    short StringID,
  41.                                    int maxLength,
  42.                                    int Font,
  43.                                    int FSize) :
  44.                    CPPFilterText (OurWindow, itsBounds, itsBounds,
  45.                                      maxLength, pass, (int)all, FALSE,
  46.                                      FALSE, Font, FSize)
  47.     {
  48.         StringHandle    tempString = GetString (StringID);
  49.         
  50.         if (tempString)
  51.           {
  52.             SetTextHandle((Handle)tempString, 
  53.                             GetHandleSize((Handle)tempString),
  54.                             TRUE);
  55.              ReleaseResource((Handle)tempString);
  56.           }
  57.         SetFilterString ("\p\r");    // no returns allowed
  58.     }
  59.  
  60. /*-----------------------------------------------------------------*/
  61.  
  62.     CPPDialogText::~CPPDialogText (void)
  63.     {    
  64.     }
  65.     
  66. /*-----------------------------------------------------------------*/
  67.  
  68.     Boolean    CPPDialogText::Member (char *className)
  69.     {
  70.         if (strcmp(className, CPPDialogText::ClassName()) == 0)
  71.           return TRUE;
  72.         else
  73.           return CPPFilterText::Member(className);
  74.     }
  75.  
  76. /*-----------------------------------------------------------------*/
  77.  
  78.     char    *CPPDialogText::ClassName (void)
  79.     {
  80.         return "CPPDialogText";
  81.     }
  82.  
  83. /*-----------------------------------------------------------------*/
  84.  
  85.     void    CPPDialogText::TargetHilite (Boolean makeTarget)
  86.     /* change the hiliteed state of the object */
  87.     /* if the text object is becoming the target, select all its text */
  88.     {
  89.         CPPFilterText::TargetHilite(makeTarget);
  90.         
  91.         if (this->IsActive())
  92.           DoSelectAll();
  93.     }
  94.  
  95. /*-----------------------------------------------------------------*/
  96.  
  97.     StringPtr    CPPDialogText::GetAsString (void)
  98.     /* allocate and return as a stringptr a copy of the text */
  99.     /* in the text edit area */
  100.     {
  101.         CharsHandle    tempHandle = GetTheText();
  102.         short        textLen = GetHandleSize(tempHandle);
  103.         StringPtr    tempPtr;
  104.         
  105.         if (tempHandle && textLen)
  106.           {
  107.               tempPtr = (StringPtr)NewPtr(textLen + 1);
  108.               if (tempPtr)
  109.                 {
  110.                   BlockMove (*tempHandle, tempPtr+1, textLen);
  111.                   *tempPtr = textLen;
  112.                 }
  113.           }    
  114.         return tempPtr;
  115.     }
  116.  
  117. /*-----------------------------------------------------------------*/
  118.  
  119.     void    CPPDialogText::SetToString (StringPtr newString)
  120.     /* set the dialog text object's contents to the passed-in string */
  121.     {
  122.         if (newString)
  123.           SetTextPtr ((Ptr)(newString+1), *newString, TRUE);
  124.     }
  125.